package com.ruoyi.project.dict.phrases.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.phrases.domain.Phrases;
import com.ruoyi.project.dict.phrases.service.IPhrasesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 常用词组Controller
 * 
 * @author shixiangwen
 * @date 2020-09-08
 */
@Controller
@RequestMapping("/dict/phrases")
public class PhrasesController extends BaseController
{
    private String prefix = "dict/phrases";

    @Autowired
    private IPhrasesService phrasesService;

    @RequiresPermissions("dict:phrases:view")
    @GetMapping()
    public String phrases()
    {
        return prefix + "/phrases";
    }

    /**
     * 查询常用词组列表
     */
    @RequiresPermissions("dict:phrases:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Phrases phrases)
    {
        startPage();
        List<Phrases> list = phrasesService.selectPhrasesList(phrases);
        return getDataTable(list);
    }

    /**
     * 导出常用词组列表
     */
    @RequiresPermissions("dict:phrases:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Phrases phrases)
    {
        List<Phrases> list = phrasesService.selectPhrasesList(phrases);
        ExcelUtil<Phrases> util = new ExcelUtil<Phrases>(Phrases.class);
        return util.exportExcel(list, "phrases");
    }

    /**
     * 新增常用词组
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存常用词组
     */
    @RequiresPermissions("dict:phrases:add")
    @Log(title = "常用词组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Phrases phrases)
    {
        return toAjax(phrasesService.insertPhrases(phrases));
    }

    /**
     * 修改常用词组
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Phrases phrases = phrasesService.selectPhrasesById(id);
        mmap.put("phrases", phrases);
        return prefix + "/edit";
    }

    /**
     * 修改保存常用词组
     */
    @RequiresPermissions("dict:phrases:edit")
    @Log(title = "常用词组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Phrases phrases)
    {
        return toAjax(phrasesService.updatePhrases(phrases));
    }

    /**
     * 删除常用词组
     */
    @RequiresPermissions("dict:phrases:remove")
    @Log(title = "常用词组", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(phrasesService.deletePhrasesByIds(ids));
    }
}
